package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.widget.RadioGroup;

import com.example.myapplication.fragments.Fragment1;
import com.example.myapplication.fragments.Fragment2;
import com.example.myapplication.fragments.Fragment3;
import com.example.myapplication.fragments.Fragment4;
import com.example.myapplication.fragments.Fragment5;

public class MainActivity extends AppCompatActivity {
    RadioGroup mRG;
    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        fragmentManager = getSupportFragmentManager();
        transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.fl_container,new Fragment1());
        transaction.commit();
        initView();
        initEvent();
    }

    private void initEvent() {
        mRG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId){
                    case R.id.rb_classmate:
                        fragmentManager = getSupportFragmentManager();
                        transaction = fragmentManager.beginTransaction();
                        transaction.replace(R.id.fl_container,new Fragment1());
                        transaction.commit();
                        break;
                    case R.id.rb_announcement:
                        fragmentManager = getSupportFragmentManager();
                        transaction = fragmentManager.beginTransaction();
                        transaction.replace(R.id.fl_container,new Fragment2());
                        transaction.commit();
                        break;
                    case R.id.rb_leave_message:
                        fragmentManager = getSupportFragmentManager();
                        transaction = fragmentManager.beginTransaction();
                        transaction.replace(R.id.fl_container,new Fragment4());
                        transaction.commit();
                        break;
                    case R.id.rb_news:
                        fragmentManager = getSupportFragmentManager();
                        transaction = fragmentManager.beginTransaction();
                        transaction.replace(R.id.fl_container,new Fragment3());
                        transaction.commit();
                        break;
                    case R.id.rb_my:
                        fragmentManager = getSupportFragmentManager();
                        transaction = fragmentManager.beginTransaction();
                        transaction.replace(R.id.fl_container,new Fragment5());
                        transaction.commit();
                        break;
                }

            }
        });
    }

    private void initView() {
        mRG = findViewById(R.id.rg_nav);

    }
}